<!DOCTYPE html>
<html>
{include file="head.html"}
<body>
<div class="header" >
    <a  class="left-btn pointer" href="{$appkucun}?m=product"><span class="iconfont icon-back"></span></a>
    <div class="title">产品管理</div>
    <a class="right-btn" href="{$appkucun}?m=product&a=add">添加</a>    
  </div>

<div class="rbox">
 <ul class="tabs-border"   id="myTab" style="margin-top:10px; margin-bottom:10px;">
    <li class="active item"><a href="#p_base"  data-toggle="tab" >基本信息</a></li>
    <li class="item"><a href="#p_other"  data-toggle="tab" >扩展信息</a></li>
    <li class="item"><a href="#p_cuxiao" data-toggle="tab">促销组合</a></li>
  </ul>
{if $data.catid}
<p class="pd-5"><a href="/index.php?m=show&id={$data.id}" target="_blank" class="btn btn-success">查看前台</a></p> 
{/if} 
<form method="post" action="{$appadmin}?m=product&a=save">
<input type="hidden" name="id" value="{$data.id}" />
<div class="tab-content"> 
<div class="tab-pane active" id="p_base"> 
<table width="100%" border="0" class="table table-bordered">
  <tr>
    <td width="100" align="right"> 标题：</td>
    <td  ><input name="title" type="text" id="title" value="{$data.title}" size="80"></td>
  </tr>
  
  <tr>
    <td width="100" align="right"> 副标题：</td>
    <td ><input name="etitle" type="text" id="etitle" value="{$data.etitle}" size="80"></td>
  </tr>
  <tr>
    <td align="right">分类：</td>
    <td>
    <select name="catid" id="catid" class="w150">
    <option value="0">请选择</option>
    {foreach item=c from=$cat_list}
                <option value="{$c.catid}" {if $data.catid eq $c.catid} selected="selected"{/if}>{$c.cname}</option>
                {foreach item=c_2 from=$c.child}
                	<option value="{$c_2.catid}" {if $data.catid eq $c_2.catid} selected="selected"{/if} class="o_c_2">|__{$c_2.cname}</option>
                    {foreach item=c_3 from=$c_2.child}
                    <option value="{$c_3.catid}" {if $data.catid eq $c_3.catid} selected="selected"{/if} class="o_c_3"> |____{$c_3.cname}</option>
                    {/foreach}
                {/foreach}
                {/foreach}
    </select>
    
    
    
    </td>
  </tr>
  
  <tr>
  	<td>所属库存</td>
    <td>
    	{get data=kclist model=kucun fun=select()}
    	<select name="kcid">
        	{foreach item=c from=$kclist}
            	<option value="{$c.kcid}" {if $c.kcid eq $data.kcid} selected{/if}>{$c.title}</option>
            {/foreach}
        </select>
    
    </td>
  </tr>
  
  <tr>
    <td align="right">图片：</td>
    <td>
    <div id="up1" url="/index.php?m=upload&a=uploadtao&dir=article&id={$data.id}">
    	<div class="btn-upload">
          <input type="file" name="upimg" id="ud"  class="btn-upload-file" onChange="uploadimg('up1')">
         </div>
 
          <input type="hidden" name="imgurl" class="imgurl" value="{$data.imgurl}">
          <span class="imgShow">
          {if $data.imgurl}
          <img src="{$data.imgurl|images_site}.100x100.jpg">
          {/if}
          </span>
      </div>
      </td>
  </tr>
  
  
  <tr>
    <td align="right">seo描述：</td>
    <td><textarea name="description" id="description" class="w600 h40">{$data.description}</textarea></td>
  </tr>
  <tr>
    <td align="right">内容：</td>
    <td><script type="text/plain" id="content" name="content" >{$data.content}</script></td>
  </tr>
 
</table>
</div>

<!--扩展信息-->
<div class="tab-pane active" id="p_other">
<table class="table">
<tr>
	<td width="100">货号：</td>
    <td><input type="text" name="goodsno" value="{$data.goodsno}" /></td>
</tr>
<tr>
	<td>价格：</td>
    <td><input type="text" name="price" value="{$data.price}" /></td>
</tr>


<tr>
	<td>市场价：</td>
    <td><input type="text" name="market_price" value="{$data.market_price}" /></td>
</tr>

<tr>
	<td>库存数量：</td>
    <td><input type="text" name="total_num" value="{$data.total_num}" /></td>
</tr>
<tr>
	<td>其他款式</td>
    <td>
    	 
        	<table class="table table-bordered">
            	<tr class="info">
                	<td width="200">款式名称</td>
                    <td width="80">价格</td>
                    <td width="80">库存</td>
                    <td width="80">销量</td>
                    <td  >操作</td>
                </tr>
                <tbody id="kslist">
                
                 
                </tbody>
                <tr class="ksitem" did="0">
                	<td><input type="text" class="ks-title w98" placeholder="款式名称"  > </td>
                    <td> <input type="text" class="ks-price w98" placeholder="价格"  ></td>
                    <td><input type="text" class="ks-total-num w98" placeholder="库存" ></td>
                    <td><input type="text" class="ks-buy-num w98" placeholder="销量" value="0"  ></td>
                    <td> <button type="button" class="ks-add btn btn-success"  >添加</button></td>
                </tr>
            </table>
        	 <script>
			 function kslist(){
				 $.get("{$appadmin}?m=product_ks&a=jlist&object_id={$data.id}",function(data){
					 var html='';
					 for(var i=0;i<data.length;i++){
						html=html+'<tr class="ksitem" did="'+data[i].id+'"><td><input type="hidden" class="ks-id" value="'+data[i].id+'"><input type="text" class="ks-title w98" value="'+data[i].title+'" placeholder="款式名称" > </td> <td> <input type="text" class="ks-price w98" value="'+data[i].price+'" placeholder="价格"  ></td>  <td><input type="text" class="ks-total-num w98" value="'+data[i].total_num+'" placeholder="库存" ></td> <td><input type="text" class="ks-buy-num w98" value="'+data[i].buy_num+'" placeholder="销量"  readonly ></td> <td> <button type="button" class="ks-add btn btn-success"  >编辑</button> <button type="button" class="ks-del btn btn-success"  >删除</button> </td> </tr>'; 
					 }
					 $("#kslist").html(html);
				 },"json");
			 }
             $(function(){
				 kslist();
				$(document).on("click",".ks-add",function(){
					var obj=$(this).parents(".ksitem");
					if($(obj).find(".ks-title").val()=='' || $(obj).find(".ks-price").val()=='' ){
						skyToast('请完善信息');
						return false;
					}
					$.post("{$appadmin}?m=product_ks&a=save&ajax=1",{
						object_id:"{$data.id}",
						id:$(obj).find(".ks-id").val(),
						title:$(obj).find(".ks-title").val(),
						price:$(obj).find(".ks-price").val(),
						total_num:$(obj).find(".ks-total-num").val(),
						buy_num:$(obj).find(".ks-buy-num").val()
					},function(data){
							skyToast('保存成功');
							if($(obj).attr("did")=="0"){
								kslist();
								$(obj).find(".ks-title").val('')
							}
					},"json")
				});
				
				$(document).on("click",".ks-del",function(){
					if(confirm('确认删除吗？')){
						var obj=$(this).parents(".ksitem");
						$.get("{$appadmin}?m=product_ks&a=delete&ajax=1&id="+$(obj).find(".ks-id").val(),function(data){
							kslist();
						})
					}
				});
			 });
             </script>
         
    </td>
</tr>
<tr>
	<td>所属品牌：</td>
    <td>
    	{get data=t_c model=brand fun=id_title()}
        <select name="brand_id">
        	<option value="0">请选择</option>
        	{foreach item=c from=$t_c}
            <option value="{$c.id}" {if $c.id eq $data.brand_id} selected="selected"{/if}>{$c.title}</option>
            {/foreach}
        </select>
    </td>
</tr>



<tr>
	<td>重量：</td>
    <td><input type="text" name="weight" value="{$data.weight}" />kg(如1.5kg)</td>
</tr>

<tr>
	<td>销售数：</td>
    <td>{$data.buy_num}</td>
</tr>


 



<tr>
    <td align="right">图集：</td>
    <td>
    <div id="webuploader" url="/admin.php?m=imgs&tablename=product&object_id={$data.id}" class="webuploader">        
        <div   class="webuploader-select">选择图片</div>
    	<div  class="webuploader-list"></div>
        <div class="ks-list"  >
         </div>
     </div>
    
 
    </td>
  </tr>
   
</table>
</div>
<!--End 扩展信息-->

  
  <div class="tab-pane active" id="p_cuxiao">
  	<table class="table">
    <tr>
	<td width="100">促销价：</td>
    <td ><input type="text" name="lower_price" value="{$data.lower_price}" /></td>
</tr>
	
     <tr>
          <td>开始时间：</td>
          <td><input type='text' name='starttime' id='starttime' value='{if $data.starttime}{$data.starttime|date:Y-m-d H:m:s}{/if}' onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" ></td>
        </tr>
        <tr>
          <td>结束时间：</td>
          <td><input type='text' name='endtime' id='endtime' value='{if $data.endtime}{$data.endtime|date:Y-m-d H:m:s}{/if}' onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" ></td>
        </tr>

    	

 <tr><td>组合产品：</td>
	<td><input type="text" style="width:600px;" name="zuhe_ids"  value="{$data.zuhe_ids}"/>(格式相关产品id：1,2,3,4,5)</td>
</tr>


<tr>
    <td align="right">组合图集：</td>
    <td><div id="webuploader_zhtj" url="/admin.php?m=imgs&tablename=product_zhtj&object_id={$data.id}" class="webuploader">        
        <div   class="webuploader-select">选择图片</div>
    	<div  class="webuploader-list"></div>
        <div class="ks-list"  >
         </div>
     </div></td>
  </tr>
    </table>
  </div>
  
   

</div>
<div class="form-btns">
 <input type="submit" name="button" id="button" class="btn" value="提交"> 
</div>
</form>
</div>
<link href="/plugin/webuploader/webuploader.css" rel="stylesheet">
<script src="/plugin/webuploader/webuploader.min.js"></script>
 <script src="/plugin/webuploader/app.js"></script>
<script>
$(function(){
	modImgsList('webuploader');
	wbupload('webuploader',"product","{$data.id}",function(){modImgsList('webuploader')});	
 
});
$(function(){
 $('#myTab a').click(function (e) {
  e.preventDefault();
  $(this).tab('show');
})

/*初始化载入属性*/
	$.get("{$appadmin}?m=product&a=attr&id={$data.id}&cat_id="+$("#attr_cat_id").val(),function(data){
				$("#attr_html").html(data);
				ajax_jsa();		
		});
	/*属性载入完毕*/
	
	$("#attr_cat_id").bind("change",function(){
		$.get("{$appadmin}?m=product&a=attr&id={$data.id}&cat_id="+$(this).val(),function(data){
				$("#attr_html").html(data);
				ajax_jsa();		
		});
	});
	
	$(".attr_item_add").live("click",function(e){
		var obj=$(this).parent(".attr_item");
		var o_t=obj.find(".attr_item_list");
		var a_len=obj.find(".attr_item_li").length;
		var html=obj.find(".attr_item_copy").html();
		html = html.replace(/\[@\]/,"["+a_len+"]");
		obj.find(".attr_item_list").append('<div class="attr_item_li">'+html+'</li>');
	});
	
	$(".attr_item_remove").live("click",function(e){
		$(this).parents(".attr_item_li").remove();
	});
	
	 
	
});
</script>
<script type="text/javascript" src="/plugin/ueditor/ueditor_simple.js?v=55}"></script>
<script type="text/javascript" src="/plugin/ueditor/ueditor.config.js?v=55}"></script>
<script language="javascript" src="/plugin/ueditor/ueditor.all.min.js?v=54"></script>

<script language="javascript">
 editor=UE.getEditor('content',options);
</script>
<script language="javascript" src="/plugin/jquery/ajaxfileupload.js"></script>
<script language="javascript" src="{const.STATIC_SITE}/static/js/upload.js"></script>
<script language="javascript" src="/plugin/My97DatePicker/WdatePicker.js"></script>
{include file='footer.html'}